//
//  ZheXianView.m
//  1243
//
//  Created by ym on 16/6/2.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "ZheXianView.h"
#import "DianZhuanCell.h"
#import "SweepViewController.h"
#import "ErWeiMaViewController.h"
#import "JudgeUserLogInTool.h"
#import "NetWorkTools.h"
#import "SCChart.h"
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

#define SCGrey         [UIColor colorWithRed:246.0/255.0 green:246.0/255.0 blue:246.0/255.0 alpha:1.0f]
#define SCLightBlue    [UIColor colorWithRed:94.0/255.0 green:147.0/255.0 blue:196.0/255.0 alpha:1.0f]
#define SCGreen        [UIColor colorWithRed:77.0/255.0 green:186.0/255.0 blue:122.0/255.0 alpha:1.0f]
#define SCTitleColor   [UIColor colorWithRed:0.0/255.0 green:189.0/255.0 blue:113.0/255.0 alpha:1.0f]
#define SCButtonGrey   [UIColor colorWithRed:141.0/255.0 green:141.0/255.0 blue:141.0/255.0 alpha:1.0f]
#define SCFreshGreen   [UIColor colorWithRed:77.0/255.0 green:196.0/255.0 blue:122.0/255.0 alpha:1.0f]
#define SCRed          [UIColor colorWithRed:245.0/255.0 green:94.0/255.0 blue:78.0/255.0 alpha:1.0f]
#define SCMauve        [UIColor colorWithRed:88.0/255.0 green:75.0/255.0 blue:103.0/255.0 alpha:1.0f]
#define SCBrown        [UIColor colorWithRed:119.0/255.0 green:107.0/255.0 blue:95.0/255.0 alpha:1.0f]
#define SCBlue         [UIColor colorWithRed:82.0/255.0 green:116.0/255.0 blue:188.0/255.0 alpha:1.0f]
#define SCDarkBlue     [UIColor colorWithRed:121.0/255.0 green:134.0/255.0 blue:142.0/255.0 alpha:1.0f]
#define SCYellow       [UIColor colorWithRed:242.0/255.0 green:197.0/255.0 blue:117.0/255.0 alpha:1.0f]
#define SCWhite        [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0f]
#define SCDeepGrey     [UIColor colorWithRed:99.0/255.0 green:99.0/255.0 blue:99.0/255.0 alpha:1.0f]
#define SCPinkGrey     [UIColor colorWithRed:200.0/255.0 green:193.0/255.0 blue:193.0/255.0 alpha:1.0f]
#define SCHealYellow   [UIColor colorWithRed:245.0/255.0 green:242.0/255.0 blue:238.0/255.0 alpha:1.0f]
#define SCLightGrey    [UIColor colorWithRed:225.0/255.0 green:225.0/255.0 blue:225.0/255.0 alpha:1.0f]
#define SCCleanGrey    [UIColor colorWithRed:251.0/255.0 green:251.0/255.0 blue:251.0/255.0 alpha:1.0f]
#define SCLightYellow  [UIColor colorWithRed:241.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0f]
#define SCDarkYellow   [UIColor colorWithRed:152.0/255.0 green:150.0/255.0 blue:159.0/255.0 alpha:1.0f]
#define SCPinkDark     [UIColor colorWithRed:170.0/255.0 green:165.0/255.0 blue:165.0/255.0 alpha:1.0f]
#define SCCloudWhite   [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0f]
#define SCBlack        [UIColor colorWithRed:45.0/255.0 green:45.0/255.0 blue:45.0/255.0 alpha:1.0f]
#define SCStarYellow   [UIColor colorWithRed:252.0/255.0 green:223.0/255.0 blue:101.0/255.0 alpha:1.0f]
#define SCTwitterColor [UIColor colorWithRed:0.0/255.0 green:171.0/255.0 blue:243.0/255.0 alpha:1.0]
#define SCWeiboColor   [UIColor colorWithRed:250.0/255.0 green:0.0/255.0 blue:33.0/255.0 alpha:1.0]
#define SCiOSGreenColor [UIColor colorWithRed:98.0/255.0 green:247.0/255.0 blue:77.0/255.0 alpha:1.0]
#define SCRandomColor   [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1.0f]


@interface ZheXianView ()<SCChartDataSource,UIWebViewDelegate>
{
    NSIndexPath *path;
    SCChart *chartView;
    
    NSArray *dataArr;
}
@property (strong, nonatomic) NSMutableArray *dataSource;
@property(nonatomic,retain)UIWebView *webView;
@end


@implementation ZheXianView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self data:@"1"];
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.dataSource = [NSMutableArray arrayWithCapacity:0];
//    NSArray *arr = @[@"一天",@"一周",@"一个月",@"三个月"];
//    for (NSInteger i = 0; i< 4; i++) {
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//     //   [self addSubview:btn];
//        btn.frame = CGRectMake(self.frame.size.width / 4 *i, 0, self.frame.size.width / 4, 30);
//        [btn addTarget:self action:@selector(BtnAction:) forControlEvents:UIControlEventTouchUpInside];
//        [btn setTitle:arr[i] forState:UIControlStateNormal];
//        
//    }
//    
//    
//    UIScrollView *scview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, self.frame.size.width,  self.frame.size.height-30)];
// //   [self addSubview:scview];
//    scview.contentSize = CGSizeMake( self.frame.size.width*2, self.frame.size.height-30);
//    scview.backgroundColor  = [UIColor redColor];
//    scview.showsVerticalScrollIndicator = NO;
//    scview.showsHorizontalScrollIndicator = NO;
//    scview.bounces = NO;
//    scview.pagingEnabled = NO;
    chartView = [[SCChart alloc] initwithSCChartDataFrame:CGRectMake(0, 0, self.frame.size.width*2, self.frame.size.height)
                                               withSource:self
                                                withStyle:SCChartLineStyle];
//    [chartView showInView:scview];
    
    self.webView = [[UIWebView alloc] initWithFrame:self.frame];
    [self addSubview:self.webView];
    //代理人
    self.webView.delegate = self;
    
    
    
    NSString *string = @"http://114.55.30.134:8089/UserCenter/EnterpriseTicketmini?number=1002";
    NSURL *url = [NSURL URLWithString:string];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    
    
    
}
- (void)data:(NSString *)type{
   
    
   
        
        
        NSDictionary *params2 = @{
                                  //
                                  @"GraphType":type
                                  };
        
        [[NetWorkTools sharedNetWorkTools] OtherobjectWithURLDict:params2 AndMenthodName:@"getGraph" completeBlock:^(id object) {
            NSString *str = object[@"BackData"];
            
            dataArr =[NetWorkTools arrayWithJsonString:str];
            NSLog(@"dataArrdataArr%@",dataArr);
            [self layoutSubviews];
        }];

  
    
    
}

- (NSArray *)getXTitles:(NSInteger )num {
    // X轴 、 横轴数据
    NSMutableArray *xTitles = [NSMutableArray array];
    
    for (NSInteger i = 0; i< dataArr.count; i++) {
        
        [  xTitles addObject:[NSString stringWithFormat:@"%@",dataArr[i][@"TradeDate"]]];
    }
    
    return xTitles;
}

#pragma mark - @required
//横坐标标题数组
- (NSArray *)SCChart_xLableArray:(SCChart *)chart {
    return [self getXTitles:dataArr.count];
}


//数值多重数组
- (NSArray *)SCChart_yValueArray:(SCChart *)chart {
    NSMutableArray *ary = [NSMutableArray array];
    
    for (NSInteger i = 0; i< dataArr.count; i++) {
        
        [  ary addObject:dataArr[i][@"TradePrice"]];
    }
    
    return @[ary];
    
    
}


#pragma mark - @optional
//颜色数组
- (NSArray *)SCChart_ColorArray:(SCChart *)chart {
    return @[SCBlue,SCRed,SCGreen];
}

#pragma mark 折线图专享功能
//标记数值区域
- (CGRange)SCChartMarkRangeInLineChart:(SCChart *)chart {
    return CGRangeZero;
}

//判断显示横线条
- (BOOL)SCChart:(SCChart *)chart ShowHorizonLineAtIndex:(NSInteger)index {
    return YES;
}

//判断显示最大最小值
- (BOOL)SCChart:(SCChart *)chart ShowMaxMinAtIndex:(NSInteger)index {
    return NO;
}

- (void)loadView{
    [self reloadInputViews];
    [self setNeedsLayout];
    [self setNeedsDisplay];
}


@end
